import React, { Component } from 'react'


export default class Count extends Component {
    state={
        carName:'s'
    }

    jia = () =>{
        let {value} = this.selectnumber
        this.props.jia(value*1)

    }
    jian = () =>{
        let {value} = this.selectnumber
        this.props.jian(value*1)
    }
    jia_odd = () =>{
        let {value} = this.selectnumber
        if(this.props.count % 2 !=1){
            this.props.jia(value*1)
        }
    }

    jia_sync = () =>{
        let {value} = this.selectnumber
        this.props.jiaAsync(value*1,500)
    }


    render() {
        return (
            <div>
                <h1>当前求和是:{this.props.count}</h1>
                <select ref={c => this.selectnumber = c}>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                </select>
                &nbsp;
                <button  onClick={this.jia}>加</button>&nbsp;
                <button onClick={this.jian}>减</button>&nbsp;
                <button onClick={this.jia_odd}>当前结果是偶数再加</button>&nbsp;
                <button onClick={this.jia_sync}>异步加</button>&nbsp;
            </div>
        )
    }
}
